/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DISCOVERY_SIMPLE_DATA_H_
#define _DISCOVERY_SIMPLE_DATA_H_

#include <fstream>
#include <iostream>
#include <map>
#include <mutex>
#include <set>
#include <vector>

#include <deps/common/Time_t.h>
#include <deps/common/GuidPrefix_t.hpp>

#include <iostream>
#include <queue>
#include <vector>

namespace evbs {
namespace ertps {
namespace rtps {
namespace ddb {

class SimpleSendData {
 public:
    SimpleSendData(GuidPrefix_t src, GuidPrefix_t dst, evbs::ertps::rtps::Time_t next_time,
                   evbs::ertps::rtps::Time_t announce)
        : src_paticipant_(src), dst_paticipant_(dst), next_time_(next_time), announce_(announce) {}

    evbs::ertps::rtps::Time_t get_next_time() const { return next_time_; }
    evbs::ertps::rtps::Time_t set_next_time(evbs::ertps::rtps::Time_t next_time) { return next_time_ = next_time; }
    evbs::ertps::rtps::Time_t get_announce() const { return announce_; }
    evbs::ertps::rtps::Time_t set_announce(evbs::ertps::rtps::Time_t announce) { return announce_ = announce; }
    GuidPrefix_t get_source_paticipant() const { return src_paticipant_; }
    GuidPrefix_t get_dest_paticipant() const { return dst_paticipant_; }
    bool is_initial_mode() const { return count < initial_announcements_count; }
    void increase_count() { count++; }
    void reset_count() { count = 0; }

    bool operator==(const SimpleSendData& other) const {
        return get_source_paticipant() == other.get_source_paticipant() &&
               get_dest_paticipant() == other.get_dest_paticipant();
    }

 private:
    GuidPrefix_t src_paticipant_;
    GuidPrefix_t dst_paticipant_;
    evbs::ertps::rtps::Time_t next_time_;
    evbs::ertps::rtps::Time_t announce_;
    int count = 0;
    static constexpr int initial_announcements_count = 3;
};

class SimpleCacheChange {
 public:
    CacheChange_t* change_;
    GuidPrefix_t src_paticipant_;
    GuidPrefix_t dst_paticipant_;
    SimpleCacheChange(CacheChange_t* change, GuidPrefix_t src_paticipant, GuidPrefix_t dst_paticipant)
        : change_(change), src_paticipant_(src_paticipant), dst_paticipant_(dst_paticipant) {}

    bool operator==(const SimpleCacheChange& other) const {
        return (src_paticipant_ == other.src_paticipant_) && (dst_paticipant_ == other.dst_paticipant_);
    }
};

} /* namespace ddb */
} /* namespace rtps */
} /* namespace ertps */
} /* namespace evbs */

#endif /* _DISCOVERY_SIMPLE_DATA_H_ */
